// 点击考勤
document.querySelectorAll('tbody')[0].children[10].children[9].children[0].click()
// 点击保存
document.getElementsByClassName('table-blue')[0].children[2].click()
// 点击确定
document.getElementById('popup_panel').children[0].click()
// 点击返回列表
document.getElementsByClassName('btn-dianming')[0].children[0].children[3].click()


// 自定点名器
// options rule
// 1.open 课堂点名页面
// 2. F12 打开控制台 
// 3. 把整个代码复制进去,点击回车
function AIclick(index) {
    // 操作策略
    var index = index;
    // console.log(index)
    const options = {
        // 点击考勤 options rule
        click_kaoqin: () => {
            document.querySelectorAll('tbody')[0].children[index].children[9].children[0].click()
        },
        // 点击保存
        click_save: () => {
            document.getElementsByClassName('table-blue')[0].children[2].click()
        },
        // 点击确定
        click_ok: () => {
            document.getElementById('popup_panel').children[0].click()
        },
        // 点击返回列表
        click_return_list: () => {
            document.getElementsByClassName('btn-dianming')[0].children[0].children[3].click()
        }
    }

    function play() {
        let start = function (r) {
            return new Promise(function (resolve, reject) {
                setTimeout(() => {
                    // options['click_kaoqin']
                    console.log('第' + index + '堂课程,点击考勤!1', r)
                    resolve(r)
                }, r);
            })
        }
        var s = start(1000).then((r) => {
            console.log(r);
            // options['click_save']
            console.log('第' + index + '堂课程,点击保存!', r)
            return r
        }).then((r) => {
            // options['click_ok']
            console.log('第' + index + '堂课程,点击确定!', r)
            return r
        }).then((r) => {
            // options['click_return_list']
            console.log('第' + index + '堂课程,点击返回列表,继续考勤!', r)
            if (index) {
                index--
            }
            return AIclick(index)
        })
    }
    play()
}

// for(let i=0;i<document.querySelectorAll('tbody')[0].children.length;i++){
AIclick(document.querySelectorAll('tbody')[0].children.length)
// }


function AIclick(index, time) {
    // 操作策略
    var index = index;
    var time = time
    // console.log(index)
    const options = {
        // 点击考勤 options rule
        click_kaoqin: () => {
            document.querySelectorAll('tbody')[0].children[index].children[9].children[0].click()
        },
        // 点击保存
        click_save: () => {
            document.getElementsByClassName('table-blue')[0].children[2].click()
        },
        // 点击确定
        click_ok: () => {
            document.getElementById('popup_panel').children[0].click()
        },
        // 点击返回列表
        click_return_list: () => {
            document.getElementsByClassName('btn-dianming')[0].children[0].children[3].click()
        }
    }

    function play() {
        let start = function () {
            return new Promise(function (resolve, reject) {
                setTimeout(() => {
                    options['click_kaoqin']
                    console.log('第' + index + '堂课程,点击考勤!1')
                    resolve()
                }, time);
            })
        }
        var s = start(time).then(() => {
            setTimeout(() => {
                options['click_save']
                console.log('第' + index + '堂课程,点击保存!')
                return time
            }, time);
        }).then(() => {
            setTimeout(() => {
                options['click_ok']
                console.log('第' + index + '堂课程,点击确定!')
                return time
            }, time);
        }).then(() => {
            setTimeout(() => {
                options['click_return_list']
                console.log('第' + index + '堂课程,点击返回列表,继续考勤!')
                if (index) {
                    index--
                } else {
                    console.log('考勤完成');
                    return
                }
                return AIclick(index)
            }, time);
        })
    }
    play()
}
AIclick(document.querySelectorAll('tbody')[0].children.length, 1000)




function AIclick(index, time) {
    // 操作策略
    var index = index;
    var time = time
    // console.log(index)
    const options = {
        // 点击考勤 options rule
        click_kaoqin: () => {
            document.querySelectorAll('tbody')[0].children[index].children[9].children[0].click()
        },
        // 点击保存
        click_save: () => {
            document.getElementsByClassName('table-blue')[0].children[2].click()
        },
        // 点击确定
        click_ok: () => {
            document.getElementById('popup_panel').children[0].click()
        },
        // 点击返回列表
        click_return_list: () => {
            document.getElementsByClassName('btn-dianming')[0].children[0].children[3].click()
        }
    }

    function play() {
        setTimeout(() => {
            // 没有就下一个
            try {
                options['click_kaoqin']()
            } catch (e) {
                index--
                AIclick(index, time)
            }
            console.log('第' + index + '堂课程,点击考勤!')
            setTimeout(() => {
                options['click_save']()
                console.log('第' + index + '堂课程,点击保存!')
                setTimeout(() => {
                    options['click_ok']()
                    console.log('第' + index + '堂课程,点击确定!')
                    setTimeout(() => {
                        options['click_return_list']()
                        console.log('第' + index + '堂课程,点击返回列表,继续考勤!')
                        if (index) {
                            index--
                            AIclick(index, time)
                        } else {
                            return ''
                        }
                    }, time);
                }, time);
            }, time);
        }, time);
    }
    play()
}
AIclick(document.querySelectorAll('tbody')[0].children.length, 100)

// beta 1.0
function AIclick(index, time) {
    var index = index;
    var time = time
    const options = {
        click_kaoqin: () => {
            document.querySelectorAll('tbody')[0].children[index].children[9].children[0].click()
        },
        click_save: () => {
            document.getElementsByClassName('table-blue')[0].children[2].click()
        },
        click_ok: () => {
            document.getElementById('popup_panel').children[0].click()
        },
        click_return_list: () => {
            document.getElementsByClassName('btn-dianming')[0].children[0].children[3].click()
        }
    }

    function play() {
        setTimeout(() => {
            options['click_kaoqin']()
            console.log('第' + index + '堂课程,点击考勤!')
            setTimeout(() => {
                options['click_save']()
                setTimeout(() => {
                    options['click_ok']()
                    setTimeout(() => {
                        options['click_return_list']()
                        console.log('第' + index + '堂课程,点击返回列表,继续考勤!')
                        if (index) {
                            index--
                            AIclick(index, time)
                        } else {
                            return ''
                        }
                        }, time);
                }, time);
            }, time)
        }, time);
    }
    play()
}
AIclick(63, 1000)

// test promise
function AIclick(index, time) {
    var index = index;
    var time = time
    let i = 0;
    setInterval(() => {i++}, 1000)
    const options = {
        click_kaoqin: () => {
            document.querySelectorAll('tbody')[0].children[index].children[9].children[0].click()
        },
        click_save: () => {
            document.getElementsByClassName('table-blue')[0].children[2].click()
        },
        click_ok: () => {
            document.getElementById('popup_panel').children[0].click()
        },
        click_return_list: () => {
            document.getElementsByClassName('btn-dianming')[0].children[0].children[3].click()
        }
    }

    function play() {
        setTimeout(() => {
            try{
                options['click_kaoqin']()
                console.log('第' + index + '堂课程,点击考勤!')
            }catch(e){
                console.log('第' + index + '堂课程,未开始考勤!')
                AIclick(--index, time)
            }
            setTimeout(() => {
                options['click_save']()
                setTimeout(() => {
                    options['click_ok']()
                    setTimeout(() => {
                        options['click_return_list']()
                        console.log('第' + index + '堂课程,点击返回列表,继续考勤!')
                        if (index) {
                            index--
                            AIclick(index, time)
                        } else {
                            alert('已经完成点名')
                            console.log('完成点名!',i)
                            var m = Number((i/60).toString().split('.')[0])
                            var s = i%60
                            console.log('总用时!'+(m?'分':'')+s+'秒')
                            return ''
                        }
                        }, time);
                }, time);
            }, time)
        }, time);
    }
    play()
}
AIclick(document.querySelectorAll('tbody')[0].children.length, 1000)